<template>
	<view class="fl-s-c nav-pt fm-ali">
		<view class="w-1"
			style="background-color: #f4f4f4; position: fixed; left: 0; top: 0; z-index: 99; overflow: hidden;">
			<u-navbar title="确认订单" :border-bottom="false" :background="{background:'#FFFFFF'}"></u-navbar>
			<image src="/static/images/user/bg284.png" class="w-1 absolute-0" style="height: 284rpx;"></image>
		</view>
		<view class="w-1 fl-s-s u-rela" style="background-color: #fff; ">
			<view class="fr-b-c w-1 p-r-30 m-t-30" @click="chooseAddress">
				<view class="fr-s-c" v-if="!default_address">
					<image src="/static/images/home/no_choose_address.png" style="width: 48rpx; height: 48rpx;"></image>
					<text class="c-00 fs-28 fm-ali">添加收货地址</text>
				</view>
				
				<view v-else class="fr-s-c">
					<image src="/static/images/home/choosed_address.png" style="width: 48rpx; height: 48rpx;"></image>
					<text
						class="c-00 fs-28 fm-ali text-line-1">{{default_address.province +default_address.city + default_address.district+ ' ' +default_address.address}}</text>
				</view>
				<image class="m-l-10" src="/static/images/user/right_arr_icon.png" style="width: 12rpx; height: 18rpx;">
				</image>
			</view>
			<image src="/static/images/home/color_bar.png" class="w-1 m-t-20" style="height: 4rpx;"></image>
			<!-- 商品信息 -->

		</view>
		<view class="w-1 m-t-20" style="background: #FFFFFF; padding: 32rpx 30rpx;">
			<view class="relative ma20" v-for="(item,index) in buyPro" :key="index">
				<!-- <view class="list-item-top">
					<image src="" class="list-item-top-icon" mode=""></image>
					<view class="list-item-top-title">
						{{item.shop_name}}
					</view>
				</view> -->
				<view class="fr-s-s margin20" v-for="(items,indexs) in item.products">
					<image :src="items.image" class="relative" mode="aspectFill"
						style="width: 162rpx; height: 162rpx; border-radius: 12rpx;"></image>
					<view class="flex-1 fl-b-s fm-ali m-l-20">
						<text class="text-line-1 c-00 fs-26">{{items.title}}</text>
						<view class="guige">
							数量:{{items.number}}
						</view>
						<view class="fr-b-c w-1 margin20">
							<view class="fr-s-c fm-ali" style="color: #FA360A; align-items: baseline;">
								<text class="fs-22">￥</text>
								<text class="fs-36">{{items.c_original_price}}</text>
							</view>
							<u-number-box :min="1" :max="Number(items.sku.c_buy_max_num)"  v-model="items.number" @change="valChange($event,items.sku.price)"></u-number-box>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="jiuwudi" v-if="OldStuff_list.length == 0">
			<view class="jiuwudi_left">
				旧物抵
			</view>
			<view class="jiuwudi_right" @tap="go_choose_jiuwu">
				选择旧物抵扣 <u-icon name="arrow-right" class="jiuwudi_right_icon"></u-icon>
			</view>
		</view> -->
		<!-- <view class="jiuwu-list" v-if="OldStuff_list.length > 0">
			<view class="jiuwu-list-top">
				<view class="jiuwudi_left">
					已选旧物
				</view>
				<view class="jiuwudi_right" @tap="go_choose_jiuwu">
					修改<u-icon name="arrow-right" class="jiuwudi_right_icon"></u-icon>
				</view>
			</view>
			<view class="jiuwu-list-view">
				<view class="jiuwu-list-view-item" v-for="(item,index) in OldStuff_list" :key="index">
					<view class="jiuwu-list-view-item-top">
						<view class="jiuwu-list-view-item-top-left">
							{{item.order_no}}
						</view>
						<view class="jiuwu-list-view-item-top-right">
							{{item.createtime_text}}
						</view>
					</view>
					<view class="jiuwu-list-view-item-min">
						<image :src="baseUrl.cdnurl+item.image" class="jiuwu-list-view-item-min-left" mode=""></image>
						<view class="jiuwu-list-view-item-min-right">
							<view class="jiuwu-list-view-item-min-right-top text-line-1">
								{{item.title}}
							</view>
							<view class="jiuwu-list-view-item-min-right-bottom">
								还能卖¥ <text
									class="jiuwu-list-view-item-min-right-bottom-num">{{item.price}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view> -->
		<!-- <view class="shangjiainfo" v-if="OldStuff_list.length > 0">
			<view class="shangjiainfo_danhao">
				<view class="shangjiainfo_danhao_left">
					<text class="bitian">*</text>物流单号
				</view>
				<input type="text" class="shangjiainfo_danhao_right" placeholder="请输入" v-model="LogisticsNum">
			</view>
			<view class="shangjiainfo_bottom">
				<view class="shangjiainfo_bottom_title">
					商家地址
				</view>
				<view class="shangjiainfo_bottom_addscce">
					北京市通州区台湖镇兰芳园一区一号楼1212
				</view>
				<view class="shangjiainfo_bottom_flex">
					<view class="shangjiainfo_bottom_flex_left">
						张怀中 <text class="shangjiainfo_bottom_flex_left_num">18003957954</text>
					</view>
					<view class="shangjiainfo_bottom_flex_right">
						复制
					</view>
				</view>
			</view>
		</view> -->
		<view class="w-1 m-t-20" style="background: #FFFFFF; padding: 32rpx 30rpx;">
			<!-- <view class="fr-b-c" style="height: 92rpx; margin-top: 28rpx;">
				<text class="fs-26" style="color: #888888;">赠送积分</text>
				<text class="fs-26 c-33">50</text>
			</view> -->
			<!-- <view class="fr-b-c" @click="toCoupon" style="height: 92rpx; margin-top: 28rpx;">
				<text class="fs-26" style="color: #888888;">优惠券</text>
				<view class="fr-s-c">
					<view class="cou-item fr-c relative" v-if="couponinfo">
						<image src="/static/images/home/goods_detail_cou_bg.png" style="left: 0; top: 0;"
							class="absolute w-1 h-1"></image>
						<text class="relative">满{{couponinfo.pay_money}}减{{couponinfo.price}}</text>
					</view>
					<image class="m-l-20" src="/static/images/user/right_arr_icon.png"
						style="width: 12rpx; height: 18rpx;">
				</view>
			</view> -->
			<!-- <view class="fr-b-c" style="height: 92rpx; margin-top: 28rpx;">
				<text class="fs-26" style="color: #888888;">使用积分抵扣</text>
				<view class="cou-item fr-c">
					<text class="fs-26" style="color: #FA360A;"
						v-if="checked && pointsinfo">使用{{pointsinfo.score}}积分，抵扣￥{{pointsinfo.price}}</text>
					<u-switch  class="m-l-20" size="30" active-color="#FA360A" v-model="checked"></u-switch>
				</view>
			</view> -->
			
			<!-- <view class="fr-b-c" style="height: 92rpx; margin-top: 28rpx;">
				<text class="fs-26" style="color: #888888;">快递费</text>
				<text class="fs-26 c-33">￥{{all_freight_price}}</text>
			</view> -->
			<view class="fr-s-c" style="height: 92rpx; margin-top: 28rpx;">
				<text class="fs-26" style="color: #888888;">备注</text>
				<input type="text" class="flex-1 fs-26" v-model="user_remark" style="margin-left: 50rpx;"
					placeholder="请输入备注信息">
			</view>
			<view class="w-1 fr-e-e" style="align-items: baseline; margin-top: 36rpx;">
				<text class="fs-26" style="color: #888888;">小计：</text>
				<view class="fr-s-c fm-ali" style="color: #FA360A; align-items: baseline;">
					<text class="fs-26">￥</text>
					<text class="" style="font-size: 44rpx;">{{pay_money | pointsPrice}}</text>
					<text class="fs-26">.{{pay_money | pointsPrice(1)}}</text>
				</view>
			</view>
			<!-- <view class="w-1 fr-e-e" style="align-items: baseline; margin-top:6rpx;" v-if="couponinfo">
				<text class="fs-26" style="color: #3DC05A;">优惠券抵扣¥8</text>
			</view> -->
		</view>
		<view class="iphonex" style="background: #FFFFFF;">
			<view class="w-1 fr-b-c p-r-30" style="height: 104rpx;">
				<view class="fr-s-c fm-ali">
					<text class="c-66 fs-24">合计</text>
					<view class="fr-s-c fm-ali" style="color: #FA360A; align-items: baseline;">
						<text class="fs-24">￥</text>
						<text class="fs-36">{{pay_money | pointsPrice}}</text>
						<text class="fs-20">.{{pay_money | pointsPrice(1)}}</text>
					</view>
				</view>
				<view class="fr-c">
					<view class="buy-btn fr-c" @click="clickSuborder">提交订单</view>
				</view>
			</view>
		</view>

		<u-popup closeable bgColor="transparent" border-radius="24" v-model="show" mode="bottom">
			<view class="fl-s-c relative w-1" style="padding: 28rpx 32rpx; background: #FFFFFF; border-radius: 24rpx;">
				<text class="c-00 fs-32" style="margin-top: 110rpx; margin-bottom: 80rpx;">支付方式</text>
				<view class="w-1 fr-b-c reason-item" v-for="(item,index) in payTypes" :key="index"
					@click="changeReason(item,index)">
					<view class="fr-s-c">
						<image :src="item.img" class="circle" style="width: 48rpx; height: 48rpx;"></image>
						<view class="m-l-20">
						{{item.name}}
						<view class="yue" v-if="item.type == 'balance'">
							可用余额：{{yu_e}}
						</view>
						</view>
					</view>
					<image
						:src="index==reasonIndex?'/static/images/shopcar/color_selected.png':'/static/images/shopcar/noc_not_select.png'"
						style="width: 36rpx; height: 36rpx;"></image>
				</view>
				<view class="sure-btn fr-c" @click="subOrder">确定</view>
			</view>
		</u-popup>

		<!-- <u-popup v-model="priceShow" mode="center" border-radius="14">
			<view class="quxiao">
				<view class="quxiao_title">
					确认离开收银台
				</view>
				<view class="quxiao_content">
					您的订单在2小时内未支付将被取消，要重新支付本次订单，请在“我的”页面，“待付款”中找到该订单进行支付
				</view>
				<view class="quxiao_content_flex">
					<view class="quxiao_content_flex_left quxiao_btn" @tap="go_back">
						确认离开
					</view>
					<view class="quxiao_content_flex_right quxiao_btn" @tap="jixu">
						继续支付
					</view>
				</view>
			</view>
		</u-popup> -->
		
		<u-popup v-model="tiaodong" mode="center" border-radius="14">
			<view class="quxiao1">
				<view class="quxiao_content1 animated11 rubberBand11">
					购买的物品不再使用，可原件回购
				</view>
				<view class="quxiao_content_flex">
					<view class="quxiao_content_flex_left quxiao_btn" @tap="zhifu_jx(1)">
						返回
					</view>
					<view class="quxiao_content_flex_right quxiao_btn" @tap="zhifu_jx(2)">
						继续支付
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="last_popup" mode="center" border-radius="14">
			<view class="quxiao1">
				<view class="quxiao_content1 animated11 rubberBand11">
					回购参考商品详情
				</view>
				<view class="quxiao_content_flex1 " @tap="go_dingdan">
					知道了
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		pointsPrice
	} from '@/utils/util.js'
	import config from '@/utils/base.js';
	export default {
		data() {
			return {
				value: 1,
				checked: false,
				show: false,
				tiaodong:false,
				payTypes: [{
						text: '余额支付',
						type:'balance',
						img: '/static/images/home/balance_pay_icon.png'
					}, {
						text: '微信支付',
						type:'wechat',
						img: '/static/images/user/ali_icon.png'
					}, {
						text: '支付宝支付',
						type:'alipay',
						img: '/static/images/user/we_icon.png'
					},
					{
						text: '银联',
						type:'apple',
						img: '/static/images/home/yinlian.png'
					},
				],
				reasonIndex: 0,
				buydata: [], // 获取页面数据的参数
				buyPro: [], // 接口返回页面数据
				ids: '', // 传给优惠券的商品id集
				total_price: 0, //接口返回总金额
				default_address: '', // 默认地址信息
				pointsinfo: '', // 积分抵扣金额详情
				// all_freight_price: 0, // 运费
				total_num: 0,
				user_remark: '', // 备注
				couponinfo: '',
				flag: false, // false 可以返回上一页 true 不可以
				priceShow: false,
				more_pay: '', // 满的金额
				discount: '', // 减少的金额
				is_combination: false, // 是否使用组合支付
				OldStuff_list: [],
				LogisticsNum: '',
				danjia: '',
				likai: true,
				token:'',
				token1:'',
				orderData:'',
				baseUrl:config,
				couponData: {},
				cartType:'',
				order_list:'',
				price:'0.00',
				payNum: 1,
				order_pay_no: '',
				order_no:'',
				order_type:'',
				yu_e:'',
				isnocondition:true,
				goodsact:'',
				// addressData:'',\
				last_popup:false,
			}
		},
		onLoad(option) {
			console.log(option)
			this.platform = option.platform || 0
			if(option.goodsact){
				this.goodsact = JSON.parse(option.goodsact) 
			}
			
			this.$api.post({
				url: '/wanlshop/pay/getBalance',
				success: res => {
					console.log(res)
					this.yu_e = res.data
					this.$store.commit('user/setUserInfo', {money: res});
					// 获取支付列表
					this.getPayment();
				}
			});
			this.optionData = JSON.parse(option.data);
			console.log(this.optionData)
			this.loadData();
			this.cartType = option.type;
			// this.buydata = JSON.parse(decodeURIComponent(e.buydata))
			// this.getInfo()
			// this.getaddress()
		},
		mounted() {
			uni.$on('jiuwulist', (res) => {
				this.OldStuff_list = res
				console.log(this.OldStuff_list)
				let num = 0
				for(let item of this.OldStuff_list){
					num += item.price
				}
				if(this.pay_money <num*2.2){
					this.isnocondition = false
					setTimeout(()=>{
						uni.showToast({
							title:'选择商品必须大于2.2倍！',
							icon:'none'
						})
					},100)
				}
			})
			uni.$on('onCoupon',coupon => {
				console.log(coupon)
				this.couponinfo = coupon
			})
		},
		filters: {
			pointsPrice
		},
		watch: {
			checked(val) {
				let arr = []
				if(this.orderData.lists.length >0){
					for(let item of  this.orderData.lists){
						for(let items of item.products){
							let data = {
								gid:items.shop_id,
								buy_pirce:items.sku.price,
								buy_nums:items.number
							}
							arr.push(data)
						}
					}
				}
				if (val) {
					this.$post({
						url: '/wanlshop/Tickets/get_use_scord',
						data: {
							buys:arr
						}
					}).then(res => {
						console.log(res)
						this.pointsinfo = res.data
					})
				} else {
					this.pointsinfo = '' // 取消使用积分 将积分信息置空
				}
			},
			// default_address: {
			// 	deep: true, //true为进行深度监听,false为不进行深度监听
			// 	handler(val) {
			// 		console.log(val, '收货地址');
			// 		// this.getFees()
			// 	}
			// },
			// couponinfo: { 
			// 	deep: true,
			// 	handler(val) {
			// 		console.log(val, '优惠券');
			// 	}
			// }
		},
		computed: {
			// all_freight_price(){
			// 	let num = 0;
			// 	for(let i in this.buyPro){
			// 		for(let k in this.buyPro[i].products){
			// 			num += Number(this.buyPro[i].products[k].freight.c_original_price- parseFloat(this.pointsinfo.price)) 
			// 		}
			// 	}
			// 	return num
			// },
			// 需要支付的金额数量
			pay_money() {
				let num = 0;
				for(let i in this.buyPro){
					for(let k in this.buyPro[i].products){
						let num_d = Number(this.buyPro[i].products[k].c_original_price)*Number(this.buyPro[i].products[k].number) 
						num += num_d
					}
				}
				// let old_num = 0
				// if(this.OldStuff_list.length > 0){
				// 	for(let k of this.OldStuff_list){
				// 		old_num+=k.price
				// 	}
				// }
				// if(this.pointsinfo){
				// 	return num+this.all_freight_price -old_num - parseFloat(this.pointsinfo.price)
				// 	return false
				// }
				return num
				
			}
		},
		onShow() {
			this.token = uni.getStorageSync('wanlshop:user').token
			this.tiaodong = false
		},

		onBackPress() {
			if (this.likai) {
				this.priceShow = true
				return true
			} else {
				return false
			}
		},
		methods: {
			getPayment(){
				let method = 'wap';
				// #ifdef APP-PLUS
				method = 'app';
				// #endif
				// #ifdef MP-BAIDU
				method = 'mini';
				// #endif
				// #ifdef MP-WEIXIN
				method = 'miniapp';
				// #endif
				// #ifdef MP-ALIPAY
				method = 'mini';
				// #endif
				// #ifdef MP-QQ
				method = 'mini';
				// #endif
				this.payTypes = [{
					name: '余额支付',
					describe: '',
					type: 'balance',
					method: 'balance',
					state: this.isbalance ? true: false, // 是否可用
					select: this.isbalance ? true: false // 是否选中
				}];
				// #ifdef H5
				if(this.$jssdk.isWechat()){
					this.payTypes.push({
						name: '公众号支付',
						describe: '推荐使用公众号支付',
						type: 'wechat',
						method: 'mp',
						state: true,
						select: this.isbalance ? false : true
					});
				}else{
					this.payTypes.push({
						name: '支付宝',
						describe: '',
						type: 'alipay',
						method: method,
						state: true,
						select: false
					}, {
						name: '微信支付',
						describe: '推荐使用微信支付',
						type: 'wechat',
						method: method,
						state: true,
						select: this.isbalance ? false : true
					});
				}
				// #endif
				// #ifndef H5
				uni.getProvider({
				    service: "payment",
				    success: (e) => {
				        e.provider.map((value) => {
							if (value == 'alipay') {
								this.payTypes.push({name: '支付宝',describe: '',type: value,method: method,state: true,select: false});
							}else if(value == 'wxpay'){
								this.payTypes.push({name: '微信支付',describe: '推荐使用微信支付',type: 'wechat',method: method,state: true,select: this.isbalance ? false : true});
							}else if(value == 'baidu'){
								this.payTypes.push({name: '百度收银台',describe: '',type: value,method: method,state: true,select: false});
							}else if(value == 'appleiap'){
								this.payTypes.push({name: 'Apple支付',describe: '',type: 'apple',method: method,state: true,select: false});
							}
				        })
				    }
				});
				// #endif
				console.log(this.payTypes)
			},
			async loadData(address_id) {
				console.log('-----')
				this.$api.post({
					url: '/wanlshop/order/getOrderGoodsList',
					loadingTip: '加载中',
					data: {
						data: this.optionData,
						platform:this.platform,
						address_id: address_id
					},
					success: res => {
						console.log(res)
						this.token1 = res.data.token;
						this.orderData = res.data.orderData;
						if (res.data.addressData) {
							this.default_address = res.data.addressData;
						}
						this.buyPro = res.data.orderData.lists
						console.log(this.default_address)
					}
				});
			},
			//添加或修改成功之后回调
			async refreshList(data, type) {
				this.$api.post({
					url: '/wanlshop/address/address',
					data: {
						data: data,
						type: 'add'
					},
					success: res => {
						this.addressData = res;
					}
				});
			},
			addAddress(type) {
				this.$wanlshop.to(`pages/UserCenter/MyAddress/MyAddress`);
			},
			go_back() {
				this.likai = false
				uni.navigateBack()
			},
			jixu() {
				this.priceShow = false
			},
			go_choose_jiuwu() {
				uni.navigateTo({
					url: '/pages/Home/GoodsDetail/ChooseOldStuff/ChooseOldStuff'
				})
			},
			payContinue() {
				this.priceShow = false
				if (this.is_combination) {
					this.reasonIndex = this.reasonIndex == 0 ? 1 : this.reasonIndex
				}
				this.show = true
			},
			// 点击提交订单按钮
			clickSuborder() {
				this.tiaodong = true
			},
			zhifu_jx(num){
				this.tiaodong = false
				if(num==1){
					return false
				}
				
				this.tj_order()
			},
			//提示完执行这里
			tj_order(){
				let address_id = this.default_address.id;
				let order_type 
				if(this.goodsact){
					order_type  = 2
				}else{
					order_type = this.OldStuff_list.length > 0?1:0
				}
				
				let data = {lists: [],order_type:order_type, address_id: address_id,gift:this.OldStuff_list,act:{
					act_available_time:this.goodsact.available_time,
					amount_withdrawal:this.goodsact.min_money,
				},is_score:this.checked?1:0},cart = [];
				this.orderData.lists.forEach((item, index)=> {
					data.lists.push({
						shop_id: item.shop_id,
						remarks: item.remarks?item.remarks:'',
						products: [],
						//店铺优惠券和其他 在下追加
						coupon_id: this.couponinfo.id?this.couponinfo.id:''
					});
					item.products.forEach(goods => {
						// 购物车数据
						cart.push({
							goods_id: goods.id,
							sku_id: goods.sku.id
						});
						// 商品数据
						data.lists[index].products.push({
							goods_id: goods.id,
							number: goods.number,
							sku_id: goods.sku.id,
							freight_id: goods.freight_id,
							platform:this.platform,
							c_father_goods_id:goods.c_father_goods_id,
							freight_id:goods.freight_id,
						});
					});
				});
				console.log(data)
				console.log(this.token)
				this.$api.post({
					url: '/wanlshop/order/addOrder',
					data: {
						order:data,
						token: this.token1
					},
					loadingTip: '提交订单中...',
					success: res => {
						console.log(res)
						this.order_list = res.data.list
						this.token = res.data.token
						console.log(this.$store.state.statistics.order.pay)
						this.$store.commit('statistics/order', {
							pay: this.$store.state.statistics.order.pay + res.data.list.length,
							whole: this.$store.state.statistics.order.whole + res.data.list.length
						});
						
						// 如果使用优惠券全局减去
						let coupon =  Object.keys(this.couponData).length;
						if (coupon != 0) {
							this.$store.commit('statistics/dynamic', {
								coupon: this.$store.state.statistics.dynamic.coupon - coupon
							});
						}
						// 大厂软件，就是这么迷幻
						if (this.cartType == 'cart') {
							this.$store.dispatch('cart/del');
						}
						let  sum = 0,order_ids = [];
						if (res.data.list.length <= 1) {
							console.log('今这里了')
							this.price = res.data.list[0].price;
							this.order_type = res.data.list[0].type;
							this.order_no = `${res.data.list[0].type == 'groups' ? '拼团':''}订单号：${res.data.list[0].order_no}`;
							this.order_pay_no = res.data.list[0].pay_no;
							this.order_id = res.data.list[0].order_id;
						}else{
							console.log('今else里了')
							res.data.list.forEach(item => {
								sum = this.$wanlshop.bcadd(sum, item.price);
								order_ids.push(item.order_id);
							});
							this.price = sum;
							this.order_id = order_ids;
							this.payNum = res.data.list.length;
							this.order_no = '合并支付 ' + res.data.list.length + '个订单';
						}
						console.log(this.payNum,'-----')
						
					}
				});
				console.log(data)
				if (this.is_combination) {
					this.reasonIndex = this.reasonIndex == 0 ? 1 : this.reasonIndex
				}
				console.log(this.reasonIndex)
				this.show = true
			},
			// 获取满减
			getFullMinus() {
				this.$get({
					url: '/zhihuan/order_price_discount',
					data: {
						order_price: this.pay_money
					}
				}).then(res => {
					this.more_pay = res.data.more_pay
					this.discount = res.data.discount
					this.priceShow = true
				})
			},
			// 优惠券
			toCoupon() {
				uni.navigateTo({
					url: '/pages/UserCenter/Coupon/Coupon?g_id=' + this.ids + '&isChoose=1&price=' + this.pay_money
				})
			},
			// // 获取运费
			// getFees() {
			// 	let pro_city = this.default_address.address.split(' ')[0] + ' ' + this.default_address.address.split(' ')[
			// 		1]
			// 	this.$get({
			// 		url: '/mainwxapp/doPageGetFreight',
			// 		data: {
			// 			buydata: JSON.stringify(this.buydata),
			// 			pro_city
			// 		}
			// 	}).then(res => {
			// 		this.all_freight_price = res.data.data.all_freight_price
			// 	})
			// },
			// // 获取默认地址
			// getaddress() {
			// 	this.$get({
			// 		url: '/order/doPageGetAddress',
			// 		data: {
			// 			suid: uni.getStorageSync('id')
			// 		}
			// 	}).then(res => {
			// 		if (res.data.data.default_address) {
			// 			this.default_address = res.data.data.default_address
			// 		}
			// 	})
			// },
			// getInfo() {
			// 	this.$get({
			// 		url: '/MainWxapp/getBuyGoodsInfo',
			// 		data: {
			// 			buydata: JSON.stringify(this.buydata)
			// 		}
			// 	}).then(res => {
			// 		var isd = this.buyPro = res.data.buyPro
			// 		for (var i in isd) {
			// 			this.ids += (this.ids == '' ? '' : ',') + isd[i].id;
			// 		}
			// 		this.total_price = res.data.total_price
			// 		this.danjia = res.data.total_price
			// 		this.total_num = res.data.total_num
			// 	})
			// },
			chooseAddress() {
				uni.navigateTo({
					url: '/pages/UserCenter/MyAddress/MyAddress?isChoose=1'
				})
			},
			valChange(e,price) {
				console.log(price)
				console.log('当前值为: ' + e.value)
				this.total_price = price * e.value
			},
			// switch打开或者关闭时触发，值为true或者false
			// 即使不监听此事件，this.checked此时也会相应的变成true或者false
			change(status) {


			},
			//订单状态文字和颜色
			orderStateExp(state) {
				let stateTip = '',
					stateTipColor = '#333';
				switch (+state) {
					case 1:
						stateTip = '等待支付';
						stateTipColor = '#f40';
						break;
					case 2:
						stateTip = '等待卖家发货';
						break;
					case 3:
						stateTip = '卖家已发货';
						break;
					case 4:
						stateTip = '交易成功';
						break;
					case 5:
						stateTip = '交易成功';
						break;
					case 6:
						stateTip = '已完成';
						break;
					case 7:
						stateTip = '订单已关闭';
						stateTipColor = '#777';
						break;
					//更多自定义
				}
				return {
					stateTip,
					stateTipColor
				};
			},
			// 改变支付方式
			changeReason(item,index) {
				console.log(item,index)
				if (this.is_combination && index == 0) return;
				this.reasonIndex = index
			},
			// 支付成功
			paySuccess(){
				// this.disabled = false;
				if(this.order_type === 'goods'){
					// console.log(this.$store.state.statistics.order.pay,this.payNum,this.$store.state.statistics.order.delive)
					this.$store.commit('statistics/order', {
						pay: this.$wanlshop.bcsub(this.$store.state.statistics.order.pay, this.payNum),
						delive: this.$wanlshop.bcadd(this.$store.state.statistics.order.delive, this.payNum)
					});
				}
				console.log('----')
				this.show = false
				this.last_popup = true
				// uni.navigateTo({
				// 	url: '/pages/UserCenter/MyOrders/MyOrders'
				// })
			},
			go_dingdan(){
				this.last_popup = false
				uni.navigateTo({
					url: '/pages/UserCenter/MyOrders/MyOrders'
				})
			},
			// 提交订单
			subOrder() {
				if (!this.default_address) return this.$u.toast('请选择收货地址');
				if (!this.reasonIndex) {
					var pay_type = 1;
					var pay_to = 0;
				} else { 
					var pay_type = 2;
					var pay_to = this.reasonIndex;
				}
				// console.log(this.reasonIndex)
				let data ={
					type:this.payTypes[this.reasonIndex].type,
					method:'app'
				}
				this.wanlPay(data);
				
			},
			async wanlPay(data, code = null){
				
				this.$api.post({
					url: '/wanlshop/pay/payment',
					data: {
						order_type: this.order_list[0].type,
						type: data.type,
						method: data.method,
						code: code,
						order_id: this.order_list[0].order_id,
						token: this.token
					},
					success: res => {
						console.log(res)
						// 余额支付/小程序支付
						switch (data.type) {
						    case 'balance':
							console.log(this.$store.state.user.money, this.price)
						        this.$store.commit('user/setUserInfo', {
						        	money: this.$wanlshop.bcsub(this.$store.state.user.money, this.price)
						        });
						        this.paySuccess();
						        break;
						    case 'wechat':
								// 微信 H5支付
						        if(data.method == 'wap'){
						        	setTimeout(() => {
						        		uni.showModal({
						        		    content: '请确认微信支付是否已完成',
						        			confirmText: '已完成',
						        			cancelText: '重新支付',
						        		    success: response=> {
						        		        if (response.confirm) {
						        		            this.paySuccess();
						        		        } else if (response.cancel) {
						        		            this.confirm();
						        		        }
						        		    }
						        		});
						        	}, 2000);
						        	// 异步查询是否支付成功
						        	window.location.href = res;
								// 微信 APP支付
								}else if(data.method == 'app'){
									uni.requestPayment({
									    provider: 'wxpay',
									    orderInfo: res.data,
									    success: (e) => {
									        console.log("success", e);
									        this.paySuccess();
									    },
									    fail: (e) => {
									        uni.showModal({
									            content: "支付失败,原因为: " + e.errMsg,
									            showCancel: false
									        })
									    },
									    complete: () => {
											// this.disabled = false;
									    }
									})
								// 微信 小程序支付
						        }else if(data.method == 'miniapp'){
									uni.requestPayment({
									    appId: res.appId,
									    nonceStr: res.nonceStr,
									    package: res.package,
									    paySign: res.paySign,
										signType: res.signType,
										timeStamp: res.timeStamp,
									    success: (e) => {
									        this.paySuccess();
									    },
									    fail: (e) => {
									        uni.showModal({
									            content: "支付失败,原因为: " + e.errMsg,
									            showCancel: false
									        })
									    }
									})
								// 微信 公众平台支付
								}else if(data.method == 'mp'){
									this.$jssdk.wxpay({
										data: res,
										success: e => {
											this.paySuccess();
										},
										fail: err => {
											if (err.errMsg == "chooseWXPay:ok") {
												this.$wanlshop.msg('支付成功');
											}else if (err.errMsg == "chooseWXPay:cancel") {
												this.$wanlshop.msg('支付失败，取消支付');
											}else if (err.errMsg == "chooseWXPay:fail") {
												this.$wanlshop.msg('支付失败');
											}
										}
									})
								}
						        break;
						    case 'alipay':
						        if(data.method == 'wap'){
									// this.disabled = false;
									if(this.order_type === 'goods'){
										this.$store.commit('statistics/order', {
											pay: this.$wanlshop.bcsub(this.$store.state.statistics.order.pay, this.payNum),
											delive: this.$wanlshop.bcadd(this.$store.state.statistics.order.delive, this.payNum)
										});
									}
									document.write(res);
								}else if(data.method == 'app'){
									uni.requestPayment({
									    provider: 'alipay',
									    orderInfo: res.data,
									    success: (e) => {
									        console.log("success", e);
									        this.paySuccess();
									    },
									    fail: (e) => {
									        uni.showModal({
									            content: "支付失败,原因为: " + e.errMsg,
									            showCancel: false
									        })
									    },
									    complete: () => {
											// this.disabled = false;
									    }
									})
								}
								break;
						} 
					}
				});
			},
			
			// 支付回调(提交订单 支付成功后调用)
			afterPay(order_id, pay_to) {
				// pay_to  0 余额 1 微信 2支付宝
				this.$get({
					url: '/Wxapps/payCallBackNotify',
					data: {
						order_id,
						payprice: this.pay_money,
						types: 'mainShop',
						flag: 0,
						fxsid: 0,
						source: 1,
						pay_to
					}
				}).then(res => {
					uni.showToast({
						title: res.msg,
						mask: true
					})
					setTimeout(() => {
						console.log('+++')
						uni.redirectTo({
							url: '/pages/UserCenter/MyOrders/MyOrders'
						})
					}, 1500)
				})
			}
		}
	}
</script>

<style>
	.ma20{
		margin-top: 20rpx;
	}
	page {
		background-color: #F4F4F4;
		padding-bottom: 150rpx;
	}
	.yue{
		font-size: 20rpx;
		color: #999999;
	}
.wlIcon-balance-pay {
	color: #fe8e2e;
}
	.common_bg {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 284rpx;
	}

	.cou-item {
		padding: 0 20rpx;
		font-size: 24rpx;
		font-family: Alibaba;
		color: #FA360A;
		height: 54rpx;
	}

	.buy-btn {
		width: 192rpx;
		height: 68rpx;
		background: #FA360A;
		box-shadow: 0rpx 6rpx 3r2px 2rpx rgba(250, 74, 20, 0.58);
		border-radius: 34rpx;
		font-size: 26rpx;
		font-family: Alibaba;
		color: #FFFFFF;
		margin-left: 14rpx;
	}

	.reason-item {
		padding: 24rpx 0;
		color: #000000;
		font-size: 28rpx;
		font-family: Alibaba;
	}

	.sure-btn {
		width: 686rpx;
		height: 100rpx;
		background: linear-gradient(246deg, #FA360A 0%, #FA8C0A 100%);
		box-shadow: 0rpx 6rpx 32rpx 2rpx rgba(250, 74, 20, 0.58);
		border-radius: 50rpx;
		font-size: 32rpx;
		font-family: Alibaba;
		color: #FFFFFF;
		margin: auto;
		margin-top: 118rpx;
		margin-bottom: 30rpx;
	}


	@-webkit-keyframes rubberBand {
		from {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}

		30% {
			-webkit-transform: scale3d(1.25, 0.75, 1);
			transform: scale3d(1.25, 0.75, 1);
		}

		40% {
			-webkit-transform: scale3d(0.75, 1.25, 1);
			transform: scale3d(0.75, 1.25, 1);
		}

		50% {
			-webkit-transform: scale3d(1.15, 0.85, 1);
			transform: scale3d(1.15, 0.85, 1);
		}

		65% {
			-webkit-transform: scale3d(0.95, 1.05, 1);
			transform: scale3d(0.95, 1.05, 1);
		}

		75% {
			-webkit-transform: scale3d(1.05, 0.95, 1);
			transform: scale3d(1.05, 0.95, 1);
		}

		to {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}
	}

	@keyframes rubberBand {
		from {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}

		30% {
			-webkit-transform: scale3d(1.25, 0.75, 1);
			transform: scale3d(1.25, 0.75, 1);
		}

		40% {
			-webkit-transform: scale3d(0.75, 1.25, 1);
			transform: scale3d(0.75, 1.25, 1);
		}

		50% {
			-webkit-transform: scale3d(1.15, 0.85, 1);
			transform: scale3d(1.15, 0.85, 1);
		}

		65% {
			-webkit-transform: scale3d(0.95, 1.05, 1);
			transform: scale3d(0.95, 1.05, 1);
		}

		75% {
			-webkit-transform: scale3d(1.05, 0.95, 1);
			transform: scale3d(1.05, 0.95, 1);
		}

		to {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}
	}

	.rubberBand {
		-webkit-animation-name: rubberBand;
		animation-name: rubberBand;
	}

	.animated {
		-webkit-animation-duration: 1s;
		animation-duration: 1s;
		-webkit-animation-fill-mode: both;
		animation-fill-mode: both;
		animation-iteration-count: infinite;
	}

	.pup-btn {
		border: 1rpx solid #FA360A;
		border-radius: 30rpx;
		padding: 10rpx 20rpx;
	}

	.list-item-top {
		display: flex;
		align-items: center;
	}

	.list-item-top-icon {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		background-color: #000000;
		margin-right: 6rpx;
	}

	.margin20 {
		margin-top: 18rpx;
	}

	.guige {
		/* width: 178rpx; */
		height: 44rpx;
		line-height: 44rpx;
		padding: 0 10rpx;
		box-sizing: border-box;
		background: #F4F4F4;
		border-radius: 22rpx;
		font-size: 20rpx;
		
	}

	/deep/.u-icon-minus {
		width: 41rpx;
		height: 42rpx !important;
		border-radius: 4rpx 0rpx 0rpx 4rpx;
		opacity: 1;
		border: 2rpx solid #F3F3F3;
		font-size: 16rpx !important;
		background-color: #fff !important;
	}

	/deep/.u-icon-plus {
		width: 41rpx;
		height: 42rpx !important;
		border-radius: 4rpx 0rpx 0rpx 4rpx;
		opacity: 1;
		border: 2rpx solid #F3F3F3;
		background-color: #fff !important;
		font-size: 16rpx !important;
		margin: 0 !important;
	}

	/deep/.u-numberbox {
		/* border: 2rpx solid #F3F3F3 !important; */
		height: 42rpx !important;
	}

	/deep/.u-number-input {
		width: 42rpx !important;
		height: 40rpx !important;
		opacity: 1 !important;
		border: 1rpx solid #F3F3F3 !important;
		background-color: #fff !important;
		margin: 0 !important;
	}

	.jiuwudi {
		width: 100%;
		height: 92rpx;
		background: #FFFFFF;
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 32rpx;
	}

	.jiuwudi_left {
		font-size: 26rpx;
		font-family: Alibaba PuHuiTi-Regular, Alibaba PuHuiTi;
		font-weight: 400;
		color: #333333;
	}

	.jiuwudi_right_icon {
		font-size: 20rpx;
		color: #000;
		margin-left: 12rpx;
	}

	.jiuwudi_right {
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #888888;
	}

	.jiuwu-list {
		width: 100%;
		/* height: 514rpx; */
		background: #FFFFFF;
		padding: 0 32rpx 28rpx 32rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}

	.jiuwu-list-top {
		width: 100%;
		height: 92rpx;
		background: #FFFFFF;
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.jiuwu-list-view-item:last-child {
		border-bottom: #F4F4F4 solid 0rpx;
	}

	.jiuwu-list-view-item {
		height: 200rpx;
		border-bottom: #F4F4F4 solid 2rpx;
		padding-top: 20rpx;
		box-sizing: border-box;
	}

	.jiuwu-list-view-item-top {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #666666;
	}

	.jiuwu-list-view-item-min-left {
		min-width: 116rpx;
		width: 116rpx;
		height: 116rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		opacity: 1;
		border: 2rpx solid #F4F4F4;
		margin-right: 20rpx;
	}

	.jiuwu-list-view-item-min {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 12rpx;
	}

	.jiuwu-list-view-item-min-right {
		width: 100%;
	}

	.jiuwu-list-view-item-min-right-bottom {
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi 2.0-65 Medium, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #E32D1D;
		margin-top: 12rpx;
	}

	.jiuwu-list-view-item-min-right-bottom-num {
		font-size: 32rpx;
	}

	.shangjiainfo {
		width: 100%;
		/* padding:30rpx; */
		background: #FFFFFF;
		margin-top: 20rpx;
	}

	.shangjiainfo_danhao {
		height: 92rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 32rpx;
		box-sizing: border-box;
		border-bottom: #F4F4F4 2rpx solid;
	}

	.shangjiainfo_danhao_left {
		font-size: 26rpx;
		font-family: Alibaba PuHuiTi-Regular, Alibaba PuHuiTi;
		font-weight: 400;
		color: #333333;
	}

	.bitian {
		color: #E32D1D;
	}

	.shangjiainfo_danhao_right::placeholder {
		color: #888888;
	}

	.shangjiainfo_danhao_right {
		height: 100%;
		width: 76%;
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #333333;
	}

	.shangjiainfo_bottom {
		padding: 0 32rpx 32rpx 32rpx;
	}

	.shangjiainfo_bottom_title {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		margin-top: 32rpx;
	}

	.shangjiainfo_bottom_addscce {
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		margin-top: 20rpx;
	}

	.shangjiainfo_bottom_flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.shangjiainfo_bottom_flex_right {
		color: #E32D1D;
	}

	.quxiao {
		width: 548rpx;
		height: 396rpx;
		background: #FFFFFF;
		border-radius: 32rpx;
		position: relative;
	}

	.quxiao_title {
		font-size: 36rpx;
		font-family: Alibaba PuHuiTi 2.0-65 Medium, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #000000;
		padding-top: 42rpx;
		text-align: center;
	}

	.quxiao_content {
		font-size: 28rpx;
		font-family: Alibaba PuHuiTi-Regular, Alibaba PuHuiTi;
		font-weight: 400;
		color: #666666;
		padding: 0 42rpx;
		margin-top: 20rpx;
		text-align: center;
	}
	.quxiao_content1 {
		font-size: 28rpx;
		font-family: Alibaba PuHuiTi-Regular, Alibaba PuHuiTi;
		font-weight: 400;
		color: #FA360A;
		padding: 0 42rpx;
		margin-top: 20rpx;
		text-align: center;
	}
	.quxiao_content_flex {
		width: 100%;
		position: absolute;
		bottom: 0;
		left: 0;
		display: flex;
		align-items: center;
		border-top: #F4F4F4 solid 2rpx;
		
		
	}
	.quxiao_content_flex1 {
		width: 100%;
		position: absolute;
		bottom: 0;
		left: 0;
		border-top: #F4F4F4 solid 2rpx;
		height: 92rpx;
		line-height: 92rpx;
		text-align: center;
		font-size: 28rpx;
		font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
		font-weight: normal;
		color: #FA360A;
		
		
	}

	.quxiao_btn {
		width: 50%;
		height: 92rpx;
		line-height: 92rpx;
		text-align: center;
		font-size: 28rpx;
		font-family: Alibaba PuHuiTi 2.0-55 Regular, Alibaba PuHuiTi 20;
		font-weight: normal;
	}

	.quxiao_content_flex_btn {
		color: #666666;
	}

	.quxiao_content_flex_left {
		color: #666666;
		border-right: #F4F4F4 solid 2rpx;
	}

	.quxiao_content_flex_right {
		color: #FA360A;
	}
	.quxiao1{
		width: 548rpx;
		height: 156rpx;
		background: #FFFFFF;
		border-radius: 32rpx;
		position: relative;
	}
	@-webkit-keyframes rubberBand11 {
		from {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}
	
		30% {
			-webkit-transform: scale3d(1.25, 0.75, 1);
			transform: scale3d(1.25, 0.75, 1);
		}
	
		40% {
			-webkit-transform: scale3d(0.75, 1.25, 1);
			transform: scale3d(0.75, 1.25, 1);
		}
	
		50% {
			-webkit-transform: scale3d(1.15, 0.85, 1);
			transform: scale3d(1.15, 0.85, 1);
		}
	
		65% {
			-webkit-transform: scale3d(0.95, 1.05, 1);
			transform: scale3d(0.95, 1.05, 1);
		}
	
		75% {
			-webkit-transform: scale3d(1.05, 0.95, 1);
			transform: scale3d(1.05, 0.95, 1);
		}
	
		to {
			-webkit-transform: scale3d(1, 1, 1);
			transform: scale3d(1, 1, 1);
		}
	}
	
	
	
	.rubberBand11 {
		-webkit-animation-name: rubberBand11;
		animation-name: rubberBand11;
	}
	
	.animated11 {
		-webkit-animation-duration: 2s;
		animation-duration: 2s;
		-webkit-animation-fill-mode: both;
		animation-fill-mode: both;
		animation-iteration-count: infinite;
	}
</style>